//
//  FEditTableViewController.m
//  YiQiTingShu
//
//  Created by dllo on 15/11/7.
//  Copyright © 2015年 直到世界的尽头. All rights reserved.
//

#import "FEditTableViewController.h"
#import "WWContentTableCell.h"
#import "WWTableContentModel.h"
#import "PublicHeader.h"
#import <MJExtension.h>
#import "AlbumFViewController.h"

#define URLString @"http://mobile.ximalaya.com/mobile/discovery/v1/recommend/editor?device=iPhone&pageId=1&pageSize=20&position=1&title=%@"

@interface FEditTableViewController ()
@property(nonatomic, strong)NSMutableArray *dataSource;
@end
static NSString *identifier = @"reuseIdentifier";
@implementation FEditTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _dataSource = [NSMutableArray array];
    [self.tableView registerClass:[WWContentTableCell class] forCellReuseIdentifier:identifier];
    [self initData];
    [self.view NightWithType:UIViewColorTypeNormal];
}

-(void)initData
{
    [AFTools getDataByURLString:@"http://mobile.ximalaya.com/mobile/discovery/v1/recommend/editor?device=iPhone&pageId=1&pageSize=20&position=1&title=%E7%8C%9C%E4%BD%A0%E5%96%9C%E6%AC%A2" WithDataBlock:^(id data) {
        [_dataSource addObjectsFromArray:[WWTableContentModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]]];
        [self.tableView reloadData];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WWContentTableCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (_dataSource.count != 0) {
        cell.model = _dataSource[indexPath.row];
    }
    
    // Configure the cell...
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 90;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WWTableContentModel *model = _dataSource[indexPath.row];
    AlbumFViewController *vc = [[AlbumFViewController alloc] init];
    vc.albumId = [NSString stringWithFormat:@"%@", model.albumId];
    vc.trackID = [NSString stringWithFormat:@"%@", model.tracks];
    vc.alumbTitel = model.title;
    [self.navigationController pushViewController:vc animated:YES];
}


@end
